
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
 */
package be.ac.ua.pats.thesisrobotica.robot.RR.sensors.utils;

//~--- non-JDK imports --------------------------------------------------------

import be.ac.ua.pats.thesisrobotica.robot.communication.Connection;
import be.ac.ua.pats.thesisrobotica.robot.communication.Sendable;

import lejos.nxt.comm.RConsole;

/**
 *
 * @author Admin
 */
public class SensorNotification extends Sendable {
    StringBuffer message = new StringBuffer();
    Connection   connection;
    String       prefix;
    String       value;

    public SensorNotification() {
        super();
    }

    public SensorNotification(Connection connection,String id) {
        try {
            this.connection = connection;
            this.prefix = id;
        } catch (NumberFormatException e) {
            RConsole.println("NumberFormatException in SensorNotification()");
        }
    }

    public void setAndSend(String value) {
        try {
            
            this.value = value;

            this.send(connection);
        } catch (NumberFormatException e) {
            RConsole.println("NumberFormatException in SensorNotification()");
        }
    }

    protected String encapsulate() {
        try {
            message = new StringBuffer();
            message.append("V,").append(prefix).append(",").append(value);

            return message.toString();
        } catch (Exception e) {
            RConsole.println("Exception in SensorNotification:encapsulate");
            return "Error";
        } 
    }
}
